package com.lbb.utils

import android.os.Build

object AppUtil {
    /**
     * 获取应用程序名称
     */
    fun getAppName(): String? {
        val application = Helper.application ?: return null
        val packageManager = application.packageManager
        val packageInfo = packageManager.getPackageInfo(application.packageName, 0)
        val labelRes = packageInfo.applicationInfo.labelRes
        return application.resources.getString(labelRes)
    }

    /**
     * 获取应用程序版本号名称
     */
    fun getVersionName(): String? {
        val application = Helper.application ?: return null
        val packageManager = application.packageManager
        val packageInfo = packageManager.getPackageInfo(application.packageName, 0)
        return packageInfo.versionName

    }

    /**
     * 获取应用程序版本号
     */
    fun getVersionCode(): Long {
        val application = Helper.application ?: return 0
        val packageManager = application.packageManager
        val packageInfo = packageManager.getPackageInfo(application.packageName, 0)

         return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
             packageInfo.longVersionCode
         } else (
             packageInfo.versionCode.toLong()
         )

    }
}